package com.fish.yssb.ui.page.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

import com.fish.yssb.Consts;
import com.fish.yssb.R;
import com.fish.yssb.app.BaseApp;
import com.fish.yssb.data.model.LoginUser;
import com.fish.yssb.ui.page.activity.base.BaseActivity;
import com.jaeger.library.StatusBarUtil;

import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Random;


/**
 * A login screen that offers login via email/password.
 */
public class AccountLoginActivity extends BaseActivity implements OnClickListener {
    private static final String TAG = AccountLoginActivity.class.getSimpleName();


    EditText et_username;
    EditText et_password;
    TextView tv_back, btn_login;
    CheckBox ck_remember;
    View ll_phonelogin, ll_register, wxlogin, qqlogin;

    public static void start(Context context) {
        Intent intent = new Intent(context, AccountLoginActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setTransparent(this);
        StatusBarUtil.setLightMode(this);
        setContentView(R.layout.activity_account_login);

        initview();

//        et_username.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                showSave();
////                showCode();
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//            }
//        });
//        et_password.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                showSave();
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//            }
//        });
//        showSave();
    }





//    private void showSave()
//    {
//        String str1 =  et_username.getText().toString().trim();
//        String str2 =  et_password.getText().toString().trim();
//
//
//        if(!str1.equalsIgnoreCase("") && !str2.equalsIgnoreCase("")
//                )
//        {
//
//            btn_login.setClickable(true);
//            btn_login.setBackgroundColor(getResources().getColor(R.color.btsel));
//        }else{
//            btn_login.setClickable(false);
//            btn_login.setBackgroundColor(getResources().getColor(R.color.btnosel));
//        }
//
//
//    }


    //初始化视图
    private void initview() {
        //登录层、下拉层、其它登录方式层
        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
        btn_login = findViewById(R.id.btn_login);

        tv_back = findViewById(R.id.tv_back);
        btn_login.setOnClickListener(this);
        tv_back.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {

        String phone = "";
        String code = "";
        String pwd = "";
        switch (view.getId()) {
            case R.id.btn_login:
                //返回
//                MainActivity.start(this);
//                finish();
                phone = et_username.getText().toString();
                pwd = et_password.getText().toString();
                if ("".equalsIgnoreCase(phone)) {
                    showToast("用户名不能为空");
                    return;
                }
                if ("".equalsIgnoreCase(pwd)) {
                    showToast("密码不能为空");
                    return;
                }
                if("admin".equalsIgnoreCase(phone)&& "1234qwer".equalsIgnoreCase(pwd)) {
                    LoginUser user = BaseApp.getInstance().user;

                    user.setUserId(phone);
                    user.setUserName(phone);
                    user.setUserType("1");
                    BaseApp.getInstance().saveUser();
                    showToast("登录成功");
                    finish();
                }else{
                    showToast("用户名或密码错误");
                }

                break;

            case R.id.tv_back:
                finish();
                break;
            default:
                break;
        }


    }


}

